/*
 * Copyright 2007 The semap project development team.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Created by myn at 29.08.2007 15:21:19.
 *
 * This class is a handler of the UPDATE command.
 *
 * $Id: UpdateCmdProc.java 439 2007-08-29 11:40:53Z Mike.Navern $
 */
package com.google.code.contactserv;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import com.google.code.contactserv.model.Contact;
import com.google.code.contactserv.model.PropertyHolder;
import com.google.code.contactserv.service.ContactService;

/**
 * @author myn
 *
 */
public class UpdateCmdProc extends CommandProcessor {

    /**
     * @param srv
     * @param lst
     */
    public UpdateCmdProc(ContactService srv, List<PropertyHolder> lst) {
        super(srv, lst);
    }

    /* 
     * 
     */
    @Override
    public void printIntroduction() {
        System.out.println("Welcome to contactserv version 1.0.");
        System.out.println("Insert a contact URI to process it or press 'ENTER' (an empty URI) to finish.");
        System.out.println("");
        System.out.println("Usage:");
        System.out.println("  1. Press 'TAB' to leave the current field value;");
        System.out.println("  2. Enter an empty value to delete the current field value.");
    }
    
    /* (non-Javadoc)
     * @see com.google.code.contactserv.CommandProcessor#doWork(java.lang.String)
     */
    @Override
    public void doWork(String uri) {
        Contact contact = srv.createContact(uri);
        
        try {
            for (Iterator<PropertyHolder> i = lst.iterator(); i.hasNext();) {
                PropertyHolder holder = (PropertyHolder) i.next();
                System.out.print(holder.getName() + ": ");
                String str = readNext();
                //setupProperties(contact, holder.getProperty(), str);
            }
            srv.add(contact);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
